Ext.define('sheath.view.base.sheetGridController', {
    extend: 'Ext.app.ViewController',

    alias: 'controller.sheetGridController',


    onClearFilters: function () {
        // The "filters" property is added to the grid (this) by gridfilters
        this.getView().filters.clearFilters();
    },

  
    changePage: function (comboBox) {
        var recordStore = this.view.store;
        var pgsize = parseInt(comboBox.getValue());
        recordStore.pageSize = pgsize;//设置store的pageSize，可以将工具栏与查询的数据同步。
        recordStore.reload({
            params: {
                start: 0,
                limit: pgsize
            }
        });
        //数据源重新加载
        //pagingToolbar.pageSize = parseInt(comboBox.getValue());
        //itemsPerPage = parseInt(comboBox.getValue());//更改全局变量itemsPerPage
        //recordStore.pageSize = itemsPerPage;//设置store的pageSize，可以将工具栏与查询的数据同步。
        //recordStore.load({
        //    params: {
        //        start: 0,
        //        limit: itemsPerPage
        //    }
        //});//数据源重新加载
        //recordStore.loadPage(1);//显示第一页
    },

    getSelectionModel: function () {
        var grid = this.getView();
        return grid.getSelectionModel();
    },
    

    /* 右键菜单 */
    onItemcontextmenu: function (view, record, item, index, e) {
        
        //this.getView().currentRecord = record;
        var ccc = this.getView().leftMenu;

        ccc.setCurrentRecord(record);

        var model = this.getView().getSelectionModel();
        model.select(index);
        e.preventDefault();  
        ccc.showAt(e.getXY());
    },

    onRefresh: function () {
        var grid = this.getView();
        grid.store.reload();
    },

    onSelectionChange: function (grid, selection) {
        var status = this.lookupReference('status'),
            message = '??',
            firstRowIndex,
            firstColumnIndex,
            lastRowIndex,
            lastColumnIndex;

        if (!selection) {
            message = 'No selection';
        }
        else if (selection.isCells) {
            firstRowIndex = selection.getFirstRowIndex();
            firstColumnIndex = selection.getFirstColumnIndex();
            lastRowIndex = selection.getLastRowIndex();
            lastColumnIndex = selection.getLastColumnIndex();

            message = 'Selected cells: ' + (lastColumnIndex - firstColumnIndex + 1) + 'x' + (lastRowIndex - firstRowIndex + 1) +
                ' at (' + firstColumnIndex + ',' + firstRowIndex + ')';
        }
        else if (selection.isRows) {
            message = 'Selected rows: ' + selection.getCount();
        }
        else if (selection.isColumns) {
            message = '选择了: ' + selection.getCount();
        }

        status.update(message);
    },


    toggleRowSelect: function (button, pressed) {
        var sel = this.getSelectionModel();
        sel.setRowSelect(pressed);
    },

    toggleCellSelect: function (button, pressed) {
        var sel = this.getSelectionModel();
        sel.setCellSelect(pressed);
    },

    toggleColumnSelect: function (button, pressed) {
        var sel = this.getSelectionModel();
        sel.setColumnSelect(pressed);
    },
    destroy: function () {

        this.callParent();
        //console.log('destroy MTTECERP.view.order.finaVerfiyGridCtrl');
    }
});